#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<int, int>
#define pil pair<int, ll>
#define pli pair<ll, int>
#define pll pair<ll, ll>

void solve(){
    int n, k;
    cin >> n >> k;
    string s, t;
    cin >> s >> t;
    vector<vector<int>> las;
    vector<int> temp(26, -1);
    las.push_back(temp);
    for(int i = 1; i < n; i++){
    	int c = s[i] - 'a';
    	temp[c] = i;
    	las.push_back(temp);
    }
    stack<pii> op, temp1;
    int res = -1;
    for(int i = n - 1; i > 0; i--){
    	int c1 = s[i] - 'a', c2 = t[i] - 'a';
    	// if(i == 4)cout << c1 << ' ' << las[i][c2] << '\n';
    	if(c1 != c2){
    		if(las[i][c2] == -1 || i - las[i][c2] > k){
    			cout << "las[i][c2]" << las[i][c2] << char('a' + c2) << '\n';
    			cout << -1 << '\n';
    			return;
    		}else{
    			res = max(res, i - las[i][c2]);
    			op.push({las[i][c2], i - las[i][c2]});
    			cout << las[i][c2] << ' ' << i - las[i][c2] << '\n';
    			i -= i - las[i][c2] - 1;
    		}
    	}
    }

    cout << res << '\n';

    for(int i = 0; i < res; i++){
    	while(!op.empty()){
    		auto [pos, cnt] = op.top();
    		op.pop();
    		s[pos + 1] = s[pos];
    		if(cnt > 1) temp1.push({pos + 1, cnt - 1});
    	}
    	while(!temp1.empty()){
    		auto t = temp1.top();
    		temp1.pop();
    		op.push(t);
    	}
    	cout << s << '\n';
    }


}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}